package com.huika.dealontop.views.common;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.huika.dealontop.R;

public class CommonNoNetView extends RelativeLayout {
    private TextView reloadBtn;
    private TextView checkBtn;

    public CommonNoNetView(Context context) {
        super(context);
    }

    public CommonNoNetView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setReload(OnClickListener onClickListener) {
        if (reloadBtn == null) {
            reloadBtn = (TextView) findViewById(R.id.click_reload);
        }
        reloadBtn.setOnClickListener(onClickListener);
    }

    public void setCheckNet(final Context context) {
        if (checkBtn == null) {
            checkBtn = (TextView) findViewById(R.id.click_checknetwork);
        }
        checkBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = null;
                // 判断手机系统的版本 即API大于10 就是3.0或以上版本及魅族手机
                if (android.os.Build.VERSION.SDK_INT > 10 && !android.os.Build.MANUFACTURER.equals("Meizu")) {
                    intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                } else {
                    intent = new Intent();
                    ComponentName component = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
                    intent.setComponent(component);
                    intent.setAction("android.intent.action.VIEW");
                }
                context.startActivity(intent);
            }
        });

    }

}
